<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>XSS Platform</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{$url.themePath}/css/bootstrap.min.css">
<link rel="stylesheet" href="{$url.themePath}/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="{$url.themePath}/css/css.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://www.bootstrapcdn.com/bootstrap/2.3.1/js/bootstrap.min.js"></script>
{literal}
<script type="text/javascript">
function SubmitContent(){
	if($("#title").val()==""){
		ShowError("模块名称不能为空");
		return false;
	}
	$("#contentForm").submit();
}
function ShowError(content){
	$("#contentShow").attr("class","alert alert-danger");
	$("#contentShow").html(content);
}
function AddKey(obj,keyname){
	var liObj=document.createElement("li");
	$(obj).parent().before(liObj);
	var input=document.createElement("input");
	$(liObj).append(input);
	var btn=document.createElement("input");
	$(liObj).append(btn);
	$(liObj).append(document.createTextNode(" "));
	btn.type="button";
	$(btn).val("添加");
	$(liObj).append(document.createTextNode(" "));
	var del=document.createElement("a");
	$(liObj).append(del);
	$(del).attr("href","javascript:void(0)");
	$(del).html("删除");
	$(btn).click(function(){
		var txt=$(input).val();
		if(txt==""){
			alert("请输入参数名");
		}else{
			$(input).remove();
			$(btn).remove();
			var checkObj=document.createElement("input");
			$(del).before(checkObj);
			checkObj.type="checkbox";
			checkObj.checked="checked";
			var keyName=keyname!=null ? keyname : "keys[]";
			$(checkObj).attr("name",keyName);
			$(checkObj).attr("value",txt);
			$(del).before(document.createTextNode(" "+txt+" "));
		}
	});
	$(del).click(function(){
		$(liObj).remove();
	});
}
</script>
{/literal}
</head>
<body>
{include file="header.html"}
<div class="container">
{include file="menus.html"}
<div class="col-sm-9">
          <div class="panel panel-default">
    	<div class="panel-heading">创建模块</div>
<form  style="padding: 10px 15px;" id="contentForm" action="{$url.root}/index.php?do=module&act=create_submit" method="post">
<input type="hidden" name="token" value="{$show.user.token}" />
<fieldset>
	<div id="contentShow"></div>

	<div class="form-group">
		<label for="title">模块名称</label>
		<input type="text" class="form-control"  name="title" id="title">
	</div>
	<p>
		<label for="description">模块描述</label><br>
		<textarea style="height:80px" class="form-control" name="description" id="description"></textarea>
	</p>
    <p>
		<label for="description">参数 (需要服务器接收的参数名)</label><br>
        <ul id="keyList">
        	{foreach from=$keys item=v}
        	<li> <input name="keys[]" value="{$v.key}" type="checkbox" checked="checked" /> {$v.key} ({$v.value})</li>
            {/foreach}
            <li><a href="javascript:void(0)" onclick="AddKey(this)">添加</a></li>
        </ul>
	</p>
	<p>
		<label for="description">配置参数 (使用此模块时需要配置的参数，如参数名为user，则代码引用：{literal}{set.user}{/literal})</label><br>
        <ul id="setkeyList">
            <li><a href="javascript:void(0)" onclick="AddKey(this,'setkeys[]')">添加</a></li>
        </ul>
	</p>
    <p>
		<label for="description">代码</label> ({literal}{projectId}为项目id,{set.***}为***配置参数{/literal})<br>
		<textarea  class="form-control" name="code" id="code" ></textarea>
	</p>
    <p>
		<label for="description">是否公开</label>
        <input type="radio" name="isOpen" value="0" checked="checked" /> 私有
        <input type="radio" name="isOpen" value="1" /> 公开
        <br>
	</p>
	<p>

		<input class="btn btn-success" type="button" value="创建" onclick="SubmitContent()"> &nbsp;&nbsp;
		<input class="btn btn-success" type="button" value="取消" onclick="history.go(-1)">
	</p>
</fieldset>
</form>
</div>
</div>
</div>
</body>
</html>